﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NoMvvm;

namespace Wizard.ViewModels
{
    public sealed class MainViewModel : ViewModel
    {
        private readonly ViewModel[] _children;
        private int _current = 0;

        public MainViewModel(FirstViewModel first, SecondViewModel second, ThirdViewModel third, FourthViewModel fourth)
        {
            This.DisplayName = "The NoMvvm Wizard";

            _children = new ViewModel[] { first, second, third, fourth };
            This.Child = first;
            SetFlags();
        }

        public void Previous()
        {
            if (This.CanPrevious)
            {
                This.Child = _children[--_current];
                SetFlags();
            }
        }

        public void Next()
        {
            if (This.CanNext)
            {
                This.Child = _children[++_current];
                SetFlags();
            }
        }

        private void SetFlags()
        {
            This.CanPrevious = _current != 0;
            This.CanNext = _current != _children.Length - 1;
        }
    }
}
